/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cgi.ndk.wf.controller;

import com.cgi.ndk.wf.generated.endToEndProcessOnly.EndToEndProcessOnlyResponse;
import com.cgi.ndk.wf.generated.endToEndTest.EndToEndTestResponse;
import com.cgi.ndk.wf.generated.humanTaskService.CompleteResponse;
import com.cgi.ndk.wf.generated.humanTaskService.LoadTaskResponse;
import com.cgi.ndk.wf.generated.humanTaskService.ReleaseResponse;
import com.cgi.ndk.wf.generated.humanTaskService.SimpleQueryResponse;
import com.cgi.ndk.wf.generated.humanTaskService.StartResponse;
import com.cgi.ndk.wf.generated.instanceManagementService.InstanceInfoType;
import com.cgi.ndk.wf.generated.instanceManagementService.PaginatedInstanceList;
import com.cgi.ndk.wf.service.TaskServiceBP;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author kovalcikm
 */
@RestController
@RequestMapping("/task")
public class TaskControllerBP {

    @Autowired
    private TaskServiceBP taskService;

    @RequestMapping(value = "/getAutomaticTasks/{page}/{limit}", produces = "application/json")
    public PaginatedInstanceList getInstances(@PathVariable("page") String page, @PathVariable("limit") String limit) {
        return taskService.getInstances(Integer.parseInt(page), Integer.parseInt(limit));
    }

    @RequestMapping(value = "/getAutomaticTasks", produces = "application/json")
    public PaginatedInstanceList getInstances() {
        return taskService.getInstances(null, null);
    }

    @RequestMapping(value = "/getAutomaticTask/{id}", produces = "application/json")
    public InstanceInfoType getPackages(@PathVariable("id") String id) {
        //todo check parameter
        return taskService.getAutomaticTask(Long.parseLong(id));
    }

    //operations with human tasks:
    @RequestMapping(value = "/getHumanTasks", produces = "application/json")
    public SimpleQueryResponse getHumanTasks() throws Exception {
        //todo check parameter
        return taskService.getHumanTasks(null, null, null);
    }

    @RequestMapping(value = "/getHumanTasks/{page}/{limit}/{date}", produces = "application/json")
    public SimpleQueryResponse getHumanTasks(@PathVariable("page") String page, @PathVariable("limit") String limit, @PathVariable("date") String date) throws Exception {
        //todo check parameter
        return taskService.getHumanTasks(Integer.parseInt(page), Integer.parseInt(limit), date);
    }

    @RequestMapping(value = "/reserve/{id}", produces = "application/json")
    public StartResponse reserve(@PathVariable("id") String id) {
        return taskService.reserve(id);
    }

    @RequestMapping(value = "/release/{id}", produces = "application/json")
    public ReleaseResponse release(@PathVariable("id") String id) {
        return taskService.release(id);
    }

    @RequestMapping(value = "/load/{id}", produces = "application/json")
    public LoadTaskResponse load(@PathVariable("id") String id) {
        return taskService.load(id);
    }

    @RequestMapping(value = "/complete/{id}", produces = "application/json")
    public CompleteResponse complete(@PathVariable("id") String id) {
        return taskService.complete(id);
    }

    @RequestMapping(value = "/endToEndProcessOnly/{id}", produces = "application/json")
    public EndToEndProcessOnlyResponse endToEndProcessOnly(@PathVariable("id") String id) {
        return taskService.endToEndProcessOnly(id);
    }

    @RequestMapping(value = "/endToEndTest/{id}", produces = "application/json")
    public EndToEndTestResponse endToEndTest(@PathVariable("id") String id) {
        return taskService.endToEndTest(id);
    }

}
